package scala

/**
  * @author pinker on 2018/3/16
  */
object Demo2 {


  def collectionMethod3(): Unit = {
    val seq = Seq(1 to 10: _*)
    val boolean1 = seq.forall(n => n > 5)
    val partions = seq.partition(num => num % 2 != 0)
    println(boolean1)
    println(partions._1.mkString("-"))
    println(partions._2.mkString("-"))
    var n = seq.foldLeft(1)((res, n) => {
      println(res + "->" + n)
      res + n
    })
    println(n)
    n = seq.fold(1)((res, n) => {
      println(res + "->" + n)
      res + n
    })
    println(n)
    n = seq.foldRight(1)((res, n) => {
      println(res + "->" + n)
      res + n
    })
    println(n)
  }

  def main(args: Array[String]): Unit = {
    //    collectionMethod1()
    //    collectionMethod2()
    //    collectionMethod3()
  }

  def collectionMethod1(): Unit = {
    val books = Seq(Book("java", 98),
      Book("scala", 240),
      Book("r", 170),
      Book("js", 19))
    val max = books.maxBy(books => books.pages)
    val min = books.minBy(books => books.pages)
    val bigthan = books.filter(books => books.pages > 120)
    println("max:\t" + max + "\tmin:\t" + min)
    println(bigthan)
  }

  def collectionMethod2(): Unit = {
    val seq = Seq(Array(1 to 10: _*), Array(20 until 25: _*), Array(100 until 109: _*))
    seq.flatMap(arr => arr).foreach(println)
    seq.flatten.foreach(println)
  }
}

case class Book(title: String, pages: Int)
